package com.study.forumsystemproject.config;

import com.study.forumsystemproject.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * program: forum-system-project
 * <p>
 * description: 拦截器的配置
 * <p>
 * author: xiaoxie
 * <p>
 * create: 2024-08-16 21:27
 *
 * @author 谢忠涵7*/
@Configuration
public class AppInterceptorConfigurer implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录拦截器
        // 添加⽤⼾登录拦截器
        registry.addInterceptor(loginInterceptor)
                // 拦截所有请求
                .addPathPatterns("/**")
                // 排除登录HTML
                .excludePathPatterns("/sign-in.html")
                // 排除注册HTML
                .excludePathPatterns("/sign-up.html")
                // 排除登录api接⼝
                .excludePathPatterns("/user/login")
                //排除注册
                .excludePathPatterns("/user/register")
                //排除获取验证码
                .excludePathPatterns("/user/getCaptcha")
                // 排除登录swagger下所有
                .excludePathPatterns("/swagger*/**")
                // 排除登录v3下所有，与swagger相关
                .excludePathPatterns("/v3*/**")
                // 排除所有静态⽂件
                .excludePathPatterns("/dist/**")
                .excludePathPatterns("/index.html")
                //排除前端代码
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/**.ico")
                .excludePathPatterns("/js/**");
    }
}
